﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Wicresoft.Busi.BizLogic;
using Wicresoft.Busi.Entity;

public partial class NewMeetingRoom_RoomApplyInfo_Day : BaseAuthenticationPage
{
    protected System.Web.UI.WebControls.Button btnPrint;
    public string strHtml = "";

    private DateTime dtDate = DateTime.Today;
    private DataTable MeetingRoomGroups;

    #region bEdit
    private bool bEdit
    {
        get
        {
            if (ViewState["bEdit"] != null)
                return (bool)ViewState["bEdit"];
            else
                return false;
        }
        set
        {
            ViewState["bEdit"] = value;
        }
    }
    #endregion

    #region bSpecial
    private bool bSpecial
    {
        get
        {
            if (ViewState["bSpecial"] != null)
                return (bool)ViewState["bSpecial"];
            else
                return false;
        }
        set
        {
            ViewState["bSpecial"] = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, System.EventArgs e)
    {
        // Put user code to initialize the page here
        if (!Page.IsPostBack)
        {
            //	this.bEdit = this.IsInRole(MeetingRoles.Apply);
            //	this.bSpecial = this.IsInRole(MeetingRoles.Register);

            dtDate = DateTime.Parse(Request.QueryString["Date"]);
            this.lblDate.Text = dtDate.ToString("yyyy年MM月dd日") + " " + Util.SceneName + "占用一览";

            MeetingRoomGroups = BLMeetingRoomGroups.GetMeetingRoomGroups(BasePage.GetDept(CurrentUser.ID).ID);
            LoadData();
        }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion

    private void LoadData()
    {
        string[] strRoomStatus = new string[] { RoomStatus.OPENED };
        DataTable dtRoom = BLMeetingRooms.GetMeetingRooms(strRoomStatus, CurrentUser.ID);

        string[] strMeetingStatus = new string[] { MeetingStatus.POST, MeetingStatus.AUDIT };
        DataTable dtApply = BLMeetingRoomApply.GetMeetingRoomApply(strRoomStatus, strMeetingStatus, dtDate, CurrentUser.ID);

        int RoomID;
        string RoomName, RoomInfo, temp, tempTip;
        for (int i = 0; i < dtRoom.Rows.Count; i++)
        {
            RoomID = int.Parse(dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ID].ToString());
            RoomName = dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + " <br>（" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_LOCATION].ToString() + "）";

            dtApply.DefaultView.RowFilter = vwMeetingRoomApply.SQLCOL_ROOMID + " = " + RoomID.ToString() + " AND " + vwMeetingRoomApply.SQLCOL_MEETINGDATE + " = '" + dtDate.ToString("yyyy-MM-dd") + "'";
            foreach (DataRowView rv in dtApply.DefaultView)
            {
                RoomInfo = "类型：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ROOMTYPECN].ToString() + Environment.NewLine;
                RoomInfo += "名称：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + Environment.NewLine;
                RoomInfo += "位置：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_LOCATION].ToString() + Environment.NewLine;
                RoomInfo += "座位数：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_SEATSCOUNT].ToString() + Environment.NewLine;
                RoomInfo += "描述：" + dtRoom.Rows[i][vwMeetingRooms.SQLCOL_DESCRIPTION].ToString() + Environment.NewLine;

                strHtml += "	<TR height=\"50\">";
                strHtml += "	    <TD width=\"78\"  align=\"center\"><FONT face=\"宋体\"><a href=\"JavaScript:OpenWin('RoomInfoView.aspx?ID=" + RoomID + "','600','420');\" title=\"" + RoomInfo + "\">" + RoomName + "</a></FONT></TD>";

                temp = rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString();
                tempTip = "会议名称：" + rv[vwMeetingRoomApply.SQLCOL_TOPIC].ToString().Trim() + Environment.NewLine;
                tempTip += "会议时间：" + rv[vwMeetingRoomApply.SQLCOL_MEETINGDATECN].ToString() + Environment.NewLine;
                tempTip += "参加人数：" + rv[vwMeetingRoomApply.SQLCOL_PEOPLECOUNT].ToString() + "人" + Environment.NewLine;
                tempTip += "出席领导：" + rv[vwMeetingRoomApply.SQLCOL_REMARK1].ToString().Trim() + Environment.NewLine;
                //	tempTip += "申请部门：" + rv[vwMeetingRoomApply.SQLCOL_GROUPNAME].ToString().Trim() + Environment.NewLine;
                tempTip += "联系人：" + rv[vwMeetingRoomApply.SQLCOL_APPLICANTNAME].ToString().Trim() + Environment.NewLine;


                strHtml += "		</TD><TD width=\"80\">" + rv[vwMeetingRoomApply.SQLCOL_STARTTIME].ToString() + "-" + rv[vwMeetingRoomApply.SQLCOL_ENDTIME].ToString() + "</TD>";

                if (this.bEdit && rv[vwMeetingRoomApply.SQLCOL_APPLICANT].ToString().Equals(CurrentUser.Name)
                    && rv[vwMeetingRoomApply.SQLCOL_STATUS].ToString().Equals(MeetingStatus.POST))
                    temp = "<a href=\"JavaScript://\" title=\"" + tempTip + "\" onclick=\"OpenWin('RoomApply.aspx?opener=InfoList&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '800', '500');\">" + temp + "</a>";
                else
                    temp = "<a href=\"JavaScript://\" title=\"" + tempTip + "\" onclick=\"OpenWin('RoomApplyView.aspx?Type=view&ApplyID=" + rv[vwMeetingRoomApply.SQLCOL_ID].ToString() + "', '800', '600');\">" + temp + "</a>";
                if (!rv[vwMeetingRoomApply.SQLCOL_REMARK2].ToString().Equals("1"))
                    strHtml += "		<TD bgcolor=\"#DDDDDD\">" + temp + "</TD>";
                else
                    strHtml += "		<TD bgcolor=\"#FEFDCD\">" + temp + "</TD>";

                strHtml += "		<TD width=\"28\">" + rv[vwMeetingRoomApply.SQLCOL_PEOPLECOUNT].ToString() + "</TD>";
                strHtml += "		<TD width=\"58\">&nbsp;" + rv[vwMeetingRoomApply.SQLCOL_REMARK1].ToString() + "</TD>";
                //	strHtml += "		<TD width=\"38\">"+ rv[vwMeetingRoomApply.SQLCOL_REMARK2CN].ToString() +"</TD>";
                strHtml += "		<TD width=\"78\">" + rv[vwMeetingRoomApply.SQLCOL_GROUPNAME].ToString() + "</TD>";
                strHtml += "		<TD width=\"48\">" + rv[vwMeetingRoomApply.SQLCOL_REMARK4].ToString() + "</TD>";
                strHtml += "		<TD width=\"58\">" + rv[vwMeetingRoomApply.SQLCOL_STATUSCN].ToString() + "</TD>";
                strHtml += "	</TR>";
            }

        }
    }
}
